<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>店铺增加</title>
<link rel="stylesheet" href="../../../files/css/layui.css" media="all">
<style type="text/css">
#goodsImg {
	position: relative;
	left: 110px;
}
</style>
</head>
<body>

	<fieldset class="layui-elem-field layui-field-title"
		style="margin-top: 20px;">
		<legend>店铺增加列表</legend>
	</fieldset>

	<form class="layui-form" action="../../../shop/saveOrUpdate.action"
		enctype="multipart/form-data" method="post">
		<div class="layui-form-item">
			<label class="layui-form-label">店家名称</label>
			<div class="layui-input-inline">
				<input type="text" name="shopName" id="shopName"
					lay-verify="required" placeholder="请输入" autocomplete="off"
					class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">店长</label>
				<div class="layui-input-inline">
					<input type="text" name="linkman" id="linkman"
						lay-verify="required" placeholder="请输入" autocomplete="off"
						class="layui-input">
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">联系电话</label>
				<div class="layui-input-inline">
					<input type="text" name="phone" id="phone" autocomplete="off"
						class="layui-input">
				</div>
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">地址</label>
			<div class="layui-input-inline">
				<textarea placeholder="请输入内容" name="shopSite" class="layui-textarea"></textarea>
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">店家类型:</label>
			<div class="layui-input-inline" id="goods">
				<select name="typeId" id="typeId" lay-verify="required"
					lay-search="">
					<option value="">------选择类型------</option>
				</select>
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">配送费</label>
			<div class="layui-input-inline">
				<input type="text" name="shopCote" id="shopCote" autocomplete="off"
					class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">是否有效</label>
			<div class="layui-input-inline">
				<select name="isva" id="isva" required="required">
					<option value="0">无效</option>
					<option value="1">有效</option>
				</select>
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">是否排序</label>
			<div class="layui-input-inline">
				<input type="number" name="sort" id="sort" required
					lay-verify="required" maxlength="12" placeholder="请输入排序号码"
					autocomplete="off" class="layui-input" class="layui-icon">
			</div>
		</div>

		<div class="layui-form-item">
			<div class="layui-inline">
				<div class="layui-upload">
					<label class="layui-form-label">上传图片</label>
					<button type="button" class="layui-btn" id="test1">上传图片</button>
					<div class="layui-upload-list" style="margin:10px 54%;">
						<img class="layui-upload-img" id="demo1" width="90px" height="90px">
						<p id="demoText" style="width:120px;margin:10px 0px;"></p>
						<input type="hidden" id="fileName" name="fileName">
					</div>
				</div>
			</div>
		</div>

		<div class="layui-form-item">
			<div class="layui-input-block">
				<input type="submit" class="layui-btn" lay-submit=""
					lay-filter="imgAdd" value="立即增加">
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>



	<script src="../../../files/js/layui.js"></script>
	<script type="text/javascript" src="../../../files/js/jquery.min.js"></script>

	<script type="text/javascript" src="../../../commom/js/base.js"></script>
	<script>
layui.use(['form','upload'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,upload = layui.upload
  ,$ = layui.$;
  form.on('submit(imgAdd)',function(){
	  layer.msg('数据加载中', {
		  icon: 1,
		  time: 1000 //2秒关闭（如果不配置，默认是3秒）
		}, function(){
			//进行渲染
			 parent.location.reload(); // 父页面刷新
		});  
  });
  
  
  form.render('select','selFilter'); 
	
	//普通图片上传
	 upload.render({
	    elem: '#test1'
	    ,url: getRootPath()+'image/getFileName.action'
	    ,before: function(obj){
	      //预读本地文件示例，不支持ie8
	      obj.preview(function(index, file, result){
	        $('#demo1').attr('src', result); //图片链接（base64）
	      });
	    }
	    ,done: function(res){
	    	
	      //如果上传失败
	      if(res.num < 0){
	        return layer.msg('上传失败');
	      }
	      //上传成功  
	      
	      $("#fileName").val(res.msg); 
	    }
	    ,error: function(){
	      //演示失败状态，并实现重传
	      var demoText = $('#demoText');
	      demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
	      demoText.find('.demo-reload').on('click', function(){
	        uploadInst.upload();
	      });
	    }
	  });
  
  
  $.ajax({
	   async:false,
	  url:getRootPath()+'type/findAll.action',
 	  data:null,
 	  success:function(msg){
 		  for(var i = 0;i<msg.length;i++){
 			$("#typeId").append("<option value="+msg[i].typeId+">"+msg[i].typeName+"</option>");
			form.render('select');
 		  }
 	  }
 	
 });
  
  
});
</script>

</body>
</html>